
const state = {
    username: '',
    userInfo: {}
}

const mutations = {
    SETUSERNAME(state, data) {
        state.username = data
    },
    SETUSERINFO(state, data) {
        state.userInfo = data
    },
    REMOVEUSERINFO(state) {
        state.userInfo = {}
    }
}

const actions = {
    setUsername({ commit }, data) {
        commit('SETUSERNAME', data)
    },
    // 获取用户信息
    // async getUserInfo({ commit }) {
    //     let result = await reqGetUserInfo()
    //     if (result.flag) {
    //         commit('SETUSERINFO', result.data)
    //     }
    // },

    // 登录后存储用户信息
    setuserinfo({ commit }, data) {
        commit('SETUSERINFO', data)

    },


    // // 退出登录
    removeuserinfo({ commit }) {
        commit('REMOVEUSERINFO')
    }


    // async loginOut({ commit }) {
    //     let result = await reqLoginOut()
    //     if (result.flag) {
    //         this.$router.push('/login')
    //     }
    // }
}

const getters = {
    avatar_url: function (state) {
        if (state.userInfo) {

            return "http://cdn.gdxywsw.club/" + state.userInfo.avatar;
        } else {

            return "http://cdn.gdxywsw.club/2022-07-31 09:31:29徐浩东.png";
        }
    },
}

export default {
    state,
    mutations,
    actions,
    getters,
}